package com.atguigu.tingshu.search.api;

import com.atguigu.tingshu.album.client.AlbumInfoFeignClient;
import com.atguigu.tingshu.common.execption.GuiguException;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.search.AlbumInfoIndex;
import com.atguigu.tingshu.search.repository.AlbumInfoRepository;
import com.atguigu.tingshu.search.service.ItemService;
import com.atguigu.tingshu.vo.search.AlbumInfoIndexVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@Tag(name = "专辑详情管理")
@RestController
@RequestMapping("api/search/albumInfo")
@Slf4j
@SuppressWarnings({"unchecked", "rawtypes"})
public class itemApiController {

	@Autowired
	private ItemService itemService;

	/**
	 * 上架专辑
	 * @param albumId 专辑id
	 */
	@GetMapping("/upperAlbum/{albumId}")
	@Operation(summary = "上架专辑")
	public Result upperAlbum(@PathVariable Long albumId){
		itemService.upperAlbum(albumId);
		return Result.ok();
	}

	/**
	 * 下架专辑
	 * @param albumId 专辑id
	 */
	@Operation(summary = "下架专辑")
	@GetMapping("/lowerAlbum/{albumId}")
	public Result lowerAlbum(@PathVariable Long albumId) {
		itemService.lowerAlbum(albumId);
		return Result.ok();
	}

	@GetMapping("/upperAlbum/batch")
	@Operation(summary = "批量上传到es")
	public Result upperAlbumBatch(){
		for (int i = 1; i <= 1581; i++) {
			itemService.upperAlbum((long) i);
		}
		return Result.ok();
	}


	// 排行榜数据预热
	// 提前将排行榜的数据从es数据库中查出来，存入redis当中，以起到数据预热的作用
	@GetMapping("/warmUpRanking")
	@Operation(summary = "排行榜数据预热")
	public Result warmUpRanking(){
		itemService.warmUpRanking();
		return Result.ok();
	}


	//TODO Request URL: http://localhost:8500/api/search/albumInfo/findRankingList/1/hotScore
	@GetMapping("/findRankingList/{category1Id}/{dimension}")
	@Operation(summary = "根据一级分类id和分类维度获取排行榜数据")
	public Result findRankingList(@PathVariable Long category1Id,
								  @PathVariable String dimension
	){
		List<AlbumInfoIndexVo> list = itemService.findRankingList(category1Id,dimension);
		return Result.ok(list);
	}
}

